<h2>Campaigns</h2>
<?php
    $this->headTitle('BizSense Campaign');
    $this->headScript()->appendFile('/js/BizSense/Crud.js'); 
    $acl = $this->acl;    
?>

<?php if  ($acl->isAllowed($this->currentUser, 'create campaigns')): ?>
<a href="<?php echo $this->url(array(
    'module'    =>'default', 
    'controller'=>'campaign',
    'action'    =>'create'
    )
  , null, true); ?>">Create Campaign</a>
<?php endif; ?>  

<fieldset class="fieldset_properties">
    <legend>
        <img src="/images/design/search.png"></li>
                     Search
     </legend>
        <?php echo $this->form; ?>
</fieldset>

<?php if (count($this->paginator)): ?>
<table class="data_table">
    <tr>
        <th>Name<?php echo $this->sortButtons("name"); ?></th>
        <th>Start Date<?php echo $this->sortButtons("start_date"); ?></th>
        <th>Assigned To<?php echo $this->sortButtons("assigned_to"); ?></th>
        <th>Action</th>
    </tr>
<?php foreach ($this->paginator as $item): ?>
<?php 
    $item = $item->toArray(); 
    $campaignId = $this->escape($item['campaign_id']);
?>
    <tr>
        <td><?php echo $this->escape($item['name']); ?></td>
        <td><?php echo $this->timestampToDocument(
                    $this->escape($item['start_date'])); ?></td>
        <td><?php echo $this->escape($item['assigned_name']); ?></td>
        <td><a href="<?php echo $this->url(
                array
                (
                    'module' => 'default',
                    'controller' => 'campaign',
                    'action' => 'viewdetails',
                    'campaign_id' => $item['campaign_id']
                ), 'default', true
            ); ?>">Details</a>

            <a href="<?php echo $this->url(
                array
                (
                    'module' => 'default',
                    'controller' => 'campaign',
                    'action' => 'edit',
                    'campaign_id' => $campaignId,
                ), 'default', true
            ); ?>">Edit</a>
            <?php
                if ($acl->isAllowed($this->currentUser, 'delete campaigns')):
                $deleteUrl = $this->url(
                    array(
                        'module' => 'default',
                        'controller' => 'campaign',
                        'action' => 'delete',
                        'campaign_id' =>$this->escape($campaignId)
                    )
                );
                echo $this->deleteButton($deleteUrl); 
          
                endif; ?>

         </td>
    </tr>
<?php endforeach; ?>
</table>
<?php endif; ?>

<?php
    if ($this->wasSearched and !count($this->paginator)) {
        echo "<br />There are no records matching the search criteria";
    }
?>

<div class="pagination">
<?php echo $this->paginationControl(
        $this->paginator, 'Sliding', 'search.phtml'
    ); ?>
</div>
<div class="div_clear"></div>

